package com.loongtech.bi.manager.system;

import com.loongtech.bi.entity.system.EntityMonitorGroupConfig;
import com.loongtech.core.jpa.manager.ManagerBase;
import com.loongtech.core.util.Utils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BiMonitorGroupConfigManager extends ManagerBase<EntityMonitorGroupConfig> {

    private static final long serialVersionUID = 1L;

    /**
     * 添加用户
     */
    public void addGroup(EntityMonitorGroupConfig e) {
        persist(e);
    }

    /**
     * 删除用户
     */
    public void delGroup(Integer id) {
        removeById(id);
    }

    /**
     * 修改用户
     */
    public void modifiyGroup(EntityMonitorGroupConfig e) {
        merge(e);
    }

    /**
     * 获取用户列表
     */
    public List<EntityMonitorGroupConfig> queryList() {
        return findByQuery("from EntityMonitorGroupConfig order by createTime desc");
    }

    /**
     * 查询用户
     */
    public List<EntityMonitorGroupConfig> searchByCriteria(EntityMonitorGroupConfig e) {
        List<Object> list = new ArrayList<>();
        StringBuilder hql = new StringBuilder(" from EntityMonitorGroupConfig e where 1=1 ");
        if (!Utils.isEmptyStr(e.getGroupName())) {
            hql.append(" and e.groupName = ?");
            list.add(e.getGroupName());
        }
//        if (!Utils.isEmptyStr(e.getNotifyType())) {
//            hql.append(" and e.notifyType like ?");
//            list.add("%" + e.getNotifyType() + "%");
//        }
        if (!Utils.isEmptyStr(e.getVoiceTemplate())) {
            hql.append(" and e.voiceTemplate = ?");
            list.add(e.getVoiceTemplate());
        }
        if (e.getGameId() != null) {
            hql.append(" and e.gameId like ?");
            list.add("%" + e.getGameId() + "%");
        }
        if (!Utils.isEmptyStr(e.getDescription())) {
            hql.append(" and e.description like ?");
            list.add("%" + e.getDescription() + "%");
        }
        hql.append(" order by e.createTime desc");
        return findByQuery(hql.toString(), list.toArray());
    }
}
